package co.sanduche.behave.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import co.sanduche.behave.BehaveApp;
import co.sanduche.behave.R;
import co.sanduche.behave.presenters.SplashscreenPresenter;

public class SplashScreenActivity extends Activity implements SplashscreenView,
		OnClickListener {

	private SplashscreenPresenter presenter;
	private ImageView imageView;
	private Handler handler;
	private static int SPLASH_TIME_OUT = 500000000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash_screen);
		presenter = new SplashscreenPresenter(this);

		imageView = (ImageView) findViewById(R.id.imgLogo);
		imageView.setOnClickListener(this);

		handler = new Handler();
		handler.postDelayed(new Runnable() {

			/*
			 * Showing splash screen with a timer. This will be useful when you
			 * want to show case your app logo / company
			 */

			@Override
			public void run() {

				presenter.goNext();
			}
		}, SPLASH_TIME_OUT);

	}

	@Override
	protected void onResume() {
		Log.e("SplashScreenActivity.onResume", "" + "");
		Log.e("SplashScreenActivity.onResume", BehaveApp.getInstance()
				.getApplicationContext().toString());
		super.onResume();

	}

	// Splash screen timer

	@Override
	public void goToStudentActivity(Long id) {

		Intent i = new Intent(this, MainActivity.class);
		i.putExtra(BehaveApp.ID_ESTUDIANTE_EXTRA, id);
		startActivity(i);
		finish();

	}

	@Override
	public void goToStudentsActivity() {
		// TODO Auto-generated method stub

	}

	@Override
	public void showError(String message) {
		// TODO Auto-generated method stub

	}

	@Override
	public void goToLoginActivity() {
		Intent i = new Intent(this, LoginActivity.class);
		startActivity(i);
		finish();

	}

	@Override
	public void onClick(View v) {
		handler.removeCallbacks(null);
		presenter.goNext();

	}

}
